package cn.gson.crmdemo.model.service;


import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crmdemo.model.dao.RegressionVoDao;
import cn.gson.crmdemo.model.dao.TkjlDao;
import cn.gson.crmdemo.model.mapper.TkjlMapper;
import cn.gson.crmdemo.model.pojo.Contract;
import cn.gson.crmdemo.model.pojo.Customer;
import cn.gson.crmdemo.model.pojo.Invoice;
import cn.gson.crmdemo.model.pojo.RegressionRecord;
import cn.gson.crmdemo.model.vo.RegressionInvoiceReturnsVo;
import cn.gson.crmdemo.model.vo.TkjlVo;


@Service
@Transactional(rollbackFor=Exception.class)
public class TkjlService {
	@Autowired
	TkjlMapper tm;
	@Autowired
	TkjlDao tdao;
	@Autowired
	RegressionVoDao red;
	
	public JSONArray selecttkjl(String rrDate){
		return tm.selecttkjl(rrDate);
		
	};
	public void addtkjl(TkjlVo to,String d) {
		BigDecimal a=to.getrAbsum();
		BigDecimal b=to.getRrMoney();
		BigDecimal c=b.subtract(a);
		RegressionRecord rd=new RegressionRecord();
		Contract ct=new Contract();
		ct.setContractId(to.getContractId());
		rd.setContract(ct);
		Invoice ie=new Invoice();
		ie.setInvoiceId(to.getInvoiceId());
		rd.setInvoice(ie);
		rd.setCustomerId(to.getCustomerId());
		rd.setRrDate(to.getRrDate());
		rd.setRrMoney(c);
		rd.setRrSate(to.getRrSate());
		rd.setrId(to.getRid());
		rd.setRrJsr(d);
		tdao.save(rd);
	}	
	/*
	 * 模糊查询
	 * 
	 */
	public JSONArray selectsj(String rq) {
		return tm.selectsj(rq);
	}
}
